package com.cloudlead.common.lang;

import com.cloudlead.common.lang.api.ResponseCode;

/**
 * All runtime exceptions inside framework should inherit from this
 *
 * @author dean
 */
public class BizRuntimeException extends RuntimeException {

    /**
     *
     */
    private static final long serialVersionUID = 4395547434330678738L;
    protected final ResponseCode baseCode;

    protected final int businessCode;

    public BizRuntimeException(ResponseCode baseCode, int businessCode) {
        this(null, null, baseCode, businessCode);
    }

    public BizRuntimeException(String message, ResponseCode baseCode, int businessCode) {
        this(message, null, baseCode, businessCode);
    }

    public BizRuntimeException(Throwable cause, ResponseCode baseCode, int businessCode) {
        this(null, cause, baseCode, businessCode);
    }

    public BizRuntimeException(String message, Throwable cause, ResponseCode baseCode, int businessCode) {
        super(message, cause);
        this.baseCode = baseCode;
        this.businessCode = businessCode;
    }


    public ResponseCode getBaseCode() {
        return baseCode;
    }

    public int getBusinessCode() {
        return businessCode;
    }

    public int getCode() {
        return baseCode.code() + businessCode;
    }
}
